package task_process

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/gcache"
	"github.com/hibiken/asynq"
)

func GetRedisCon() *asynq.RedisClientOpt {
	ret, _ := gcache.Get("task_queue_redis")
	if ret == nil {
		retitem := new(asynq.RedisClientOpt)
		redisInfo := g.Cfg().GetString("task_queue.redis")
		pwd := g.Cfg().GetString("task_queue.pwd")
		dbnum := g.Cfg().GetInt("task_queue.dbnum")
		poolSize := g.Cfg().GetInt("task_queue.poolsize")

		retitem.Addr = redisInfo
		retitem.Password = pwd
		retitem.PoolSize = poolSize
		retitem.DB = dbnum
		gcache.Set("task_queue_redis", retitem, 0)
		return retitem
	} else {
		return ret.(*asynq.RedisClientOpt)
	}
}
